<? 
if (isset($_GET['year']) && isset($_GET['month']) && isset($_GET['day']) && isset($_GET['id'])){// && isset($_GET['st']) ){
	$year = $_GET['year'];
	$month= $_GET['month'];
	$day  = $_GET['day'];
	$id   = $_GET['id'];
//	$start= str_replace('\\\'',"",$_GET['st']);
	
	$uri = "index.php?page=predef&amp;year=$year&amp;month=$month&amp;day=$day&amp;id=$id";//&amp;start=$start";
	$output = "<div id='time'><strong>$day.$month.$year</strong><br/>";
	$output .= "Velg tidspunkt: <form action=\"$uri\" method=\"post\" ><select id='klokke' name='time'>";
	
	for($i=0; $i<24; $i++){
		if ($i < 10){
			$output.= '<option value=0'.$i.'>0'.$i.':00</option>';
		} else {
			$output.= '<option value='.$i.'>'.$i.':00</option>';
		}
	}
	$output.='</select><input type="submit" value="OK" /></form></div>';

	echo $output;


		/*** .... ---- .... **/
} else if (isset($_GET['month']) && isset($_GET['year']) && isset($_GET['id'])){ //&& isset($_GET['start'])){
		/*** .... ---- .... **/


$id = $_GET['id'];
//$st = $_GET['start'];

$output = '';
$month = $_GET['month'];
$year = $_GET['year'];
	
if($month == '' && $year == '') { 
	$time = time();
	$month = date('n',$time);
    $year = date('Y',$time);
}

$date = getdate(mktime(0,0,0,$month,1,$year));
$today = getdate();
$hours = $today['hours'];
$mins = $today['minutes'];
$secs = $today['seconds'];

if(strlen($hours)<2) $hours="0".$hours;
if(strlen($mins)<2) $mins="0".$mins;
if(strlen($secs)<2) $secs="0".$secs;

$days=date("t",mktime(0,0,0,$month,1,$year));
$start = $date['wday'];
$name = $date['month'];
$year2 = $date['year'];
$offset = $days + $start - 1;
 
 
if($month==12) { 
	$next=1; 
	$nexty=$year + 1; 
} else { 
	$next=$month + 1; 
	$nexty=$year; 
}

if($month==1) { 
	$prev=12; 
	$prevy=$year - 1; 
} else { 
	$prev=$month - 1; 
	$prevy=$year; 
}

if($offset <= 28) $weeks=28; 
elseif($offset > 35) $weeks = 42; 
else $weeks = 35; 

$output .= "
<table class='cal' cellspacing='1'>
<tr>
	<td colspan='7'>
		<table class='calhead'>
		<tr>
			<td>";
if(($date[mon] > $today[mon]) || $date[year]>$today[year] )
	$output.="<a href='#' onclick='javascript:navigate($prev,$prevy)'><img src='ajax/calendar/calLeft.gif'></a>";		
$output.= " <a href='#' onclick='javascript:navigate(\"\",\"\")'><img src='ajax/calendar/calCenter.gif'></a> <a href='#' onclick='javascript:navigate($next,$nexty)'><img src='ajax/calendar/calRight.gif'></a>
			</td>
			<td align='right'>
				<div>$name $year2</div>
			</td>
		</tr>
		</table>
	</td>
</tr>
<tr class='dayhead'>
	<td>Man</td>
	<td>Tir</td>
	<td>Ons</td>
	<td>Tor</td>
	<td>Fre</td>
	<td>Lør</td>
	<td>Søn</td>
</tr>";

$col=1;
$cur=1;
$next=0;

for($i=1;$i<=$weeks;$i++) { 
	if($next==3) $next=0;
	if($col==1) $output.="<tr class='dayrow'>";
  	
	
	$output.="<td valign='top'";
		
	if($i <= ($days+($start-1)) && $i >= $start) {
		if( ($date[year]>$today[year]) || ($date[mon]>$today[mon]) || ($cur >= $today[mday])){
			$output.= " onclick='javascript:selecttime($date[year],$date[mon],$cur,$id)'";//,\"$st\")'";
		} else {
			$output.="style='background:#ccc'";
		}
		$output.=">";
		$output.="<div class='day'><b";
		if(($cur==$today[mday]) && ($name==$today[month]))
			$output.=" style='color:#C00'";

		$output.=">$cur</b></div></td>";
		$cur++; 
		$col++; 
		
	} else { 
		$output.=">&nbsp;</td>";
		$col++; 
	}  

    if($col==8) { 
	    $output.="</tr>";
	    $col=1; 
    }
}

$output.="</table>";

echo $output;
} else {
	echo "error<br/>";
	print_r($_GET);
}
?>
